package com.dxf.sysadmin.utils;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.dxf.sysadmin.entity.EvaluateTypeBo;
import com.dxf.sysadmin.entity.EvaluteType;
import com.dxf.sysadmin.mapper.AddEvaluateItemMapper;
import com.dxf.sysadmin.mapper.AddEvaluateTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ExcelTypeListener extends AnalysisEventListener<EvaluateTypeBo> {

    private static AddEvaluateTypeMapper addEvaluateTypeMapper; //关键2

    @Autowired  //关键3
    public void setAddEvaluateTypeMapper (AddEvaluateTypeMapper addEvaluateTypeMapper){
        ExcelTypeListener.addEvaluateTypeMapper = addEvaluateTypeMapper;
    }
    @Override
    public void invoke(EvaluateTypeBo data, AnalysisContext context) {
        EvaluteType evaluteType = new EvaluteType();
        evaluteType.setName(data.getName());
        evaluteType.setSortCode(data.getSortCode());
        evaluteType.setWeight(data.getWeight());
        addEvaluateTypeMapper.InsertEvaluateType(evaluteType);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {

    }
}
